<template>
  <div>
    <div class="main">
      <div class="contain">
        <div class="header">XXX后台管理系统</div>
        <div class="content">
          <div class="block">
            <el-input placeholder="请输入内容" v-model="loginParams.userName" autocomplete="off">
              <template slot="prepend">
                <i class="el-icon-user"></i>
              </template>
            </el-input>
          </div>
          <div class="block">
            <el-input placeholder="请输入密码" v-model="loginParams.password" show-password autocomplete="off">
              <template slot="prepend">
                <i class="el-icon-lock"></i>
              </template>
            </el-input>
          </div>
          <div>
             <el-button class="login-btn" type="primary" @click="loginIn">登录</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  name: 'Login',
  data () {
    return {
      loginParams: {
        userName: '',
        password: ''
      }
    }
  },
  mounted () {
    window.addEventListener('keyup', this.keyupEnter, false)
  },
  methods: {
    loginIn () {
      if (!this.loginParams.userName) {
        this.$message.error('用户名不能为空')
        return
      }
      if (!this.loginParams.password) {
        this.$message.error('密码不能为空')
        return
      }
      // 调用登录接口
      this.$message({
        message: '登录成功',
        type: 'success'
      })
      this.$router.push({path: '/index'})
    },
    keyupEnter () {
      let self = this
      if (window.event.keyCode === 13) {
        self.loginIn()
      }
    }
  },
  destroyed () {
    window.removeEventListener('keyup', this.keyupEnter)
  }
}
</script>

<style lang="stylus" scoped>
@import "~common/styl/variable.styl"
.main
  position fixed
  left 0
  right 0
  top 0
  bottom 0
  background-color #313237
  // background-image url('./images/bg.jpg')
  background-size cover
  background-position center
  background-repeat no-repeat
  .contain
    position fixed
    left 50%
    top 50%
    width 400px
    transform translate(-50%, -50%)
    padding 0 16px
    .header
      width 100%
      margin-bottom 24px
      font-size 24px
      color $white_v1
      letter-space 2px
      text-align center
    .content
      width 100%
      height: auto
      border-radius 3px
      .block
        margin-bottom 16px
        /deep/ .el-input__inner
          border 1px solid $gray-v6 !important
        /deep/ .el-icon-user, .el-icon-lock
          font-size 20px
      .login-btn
        width 100%
        font-size 16px
        letter-spacing 2px
</style>
